<template>
    <div>
        <el-row>
            <el-col :span="24" class="base-mian-cell" v-if="cumAmountFlag">
                <div class="base-mian-cell-title clearfix">
                    <div class="left fl">
                        <span class="line">|</span>
                        <span class="tips">累计保额</span>
                    </div>
                    <div class="right fr" @click="changeView">
                        <i class="el-icon-circle-close"></i>
                    </div>
                </div>
                <div class="base-mian-cell-main">
                    <el-row>
                        <el-col :span="6" v-for="(item, index) in amounts" v-if="index < 7" class="mb10">
                            <el-col :span="14">{{item.name}}:</el-col>
                            <el-col :span="10">{{item.total.toFixed(2)}}</el-col>
                        </el-col>
                        <el-col :span="6" class="mb10">
                            <div class="txt-line" @click="more" title="更多">......</div>
                        </el-col>
                    </el-row>

                </div>
            </el-col>
        </el-row>


        <!-- 展示所有的保额信息 -->
        <el-dialog
                title="累计保额"
                :visible.sync="opinionDialogVisible2"
                width="50%"
                center>
            <el-row >
                <el-col :span="24"  class="mb10">
                     <el-col :span="8" class="txt-right">被保险人:</el-col>
                    <el-col :span="8"><el-input  v-model="name" disabled></el-input></el-col>
                    <!-- <el-col :span="8" style="padding-left:10px;"><el-button @click="insuranceShow" style="color: #68A3FC">主约险种累计保额</el-button></el-col> -->
                </el-col>
            </el-row>
            <!-- <el-row >
                <el-col :span="24"  class="mb10">
                    <el-col :span="8" class="txt-right">&nbsp;</el-col>
                    <el-col :span="8"><el-button @click="insuranceShow" style="color: #68A3FC">主约险种累计保额</el-button></el-col>
                    <el-col :span="8"></el-col>
                </el-col>
            </el-row> -->
            <el-row v-for="item in amounts">
                <el-col :span="24"  class="mb10">
                    <el-col :span="8" class="txt-right">{{item.name}}:</el-col>
                    <el-col :span="8"><el-input  v-model="item.total" disabled></el-input></el-col>
                    <el-col :span="8" style="padding-left:10px;"><el-button @click="details(item)"  style="color: #68A3FC">详情</el-button></el-col>
                </el-col>
            </el-row>

            <span slot="footer" class="dialog-footer">
            <el-button @click="showLogs" class="ml10">查看日志</el-button>
            <el-button @click="opinionDialogVisible2 = false">返 回</el-button>
        </span>
        </el-dialog>

        <!-- 详情 -->
        <el-dialog
                title="详情"
                :visible.sync="opinionDialogVisible1"
                width="60%"
                center>
            <el-row >
                <el-table :data="crts" class="mt10">
                    <el-table-column property="chdrnum" label="保单号码"  min-width="120" show-overflow-tooltip></el-table-column>
                    <el-table-column property="clntnum" label="客户号"  min-width="120" show-overflow-tooltip></el-table-column>
                    <el-table-column property="crtable" label="险种"  min-width="120" show-overflow-tooltip></el-table-column>
                    <el-table-column property="suminsorg" label="原始保额"  min-width="120" show-overflow-tooltip></el-table-column>
					<el-table-column property="count" label="累计保额"  min-width="120" show-overflow-tooltip></el-table-column>
					<el-table-column  v-if="'Y'== showAmount" label="本地原始保额" min-width="120" show-overflow-tooltip>
						<template slot-scope="scope">
							<span v-if="scope.row.realsuminsorg" > {{scope.row.realsuminsorg}}</span>
						</template>
					</el-table-column>
					<el-table-column  v-if="'Y'== showAmount" label="本地累计保额" min-width="120" show-overflow-tooltip>
						<template slot-scope="scope">
							<span v-if="scope.row.realCount" > {{scope.row.realCount}}</span>
						</template>
					</el-table-column>
                    <el-table-column property="hoissdte" label="生效日期"  min-width="160" show-overflow-tooltip></el-table-column>
                    <el-table-column :formatter="changeValue" property="reinsdate" label="复效日期"  min-width="160" show-overflow-tooltip></el-table-column>
                </el-table>
            </el-row>

            <span slot="footer" class="dialog-footer">
            <el-button @click="opinionDialogVisible1 = false">返 回</el-button>
        </span>
        </el-dialog>


        <!-- 主约险种累计保额 -->
        <!-- <el-dialog
                title="主约险种累计保额"
                :visible.sync="opinionDialogVisible3"
                width="40%"
                center>
            <el-row >
                <el-col :span="24"  class="mb10">
                    <el-col :span="4" class="text_right">被保险人</el-col>
                    <el-col :span="8"><el-input  v-model="name" disabled></el-input></el-col>
                </el-col>
            </el-row>
            <el-table :data="master">
                <el-table-column property="crtable" label="险种"  min-width="120" show-overflow-tooltip></el-table-column>
                <el-table-column property="count" label="累计保额"  min-width="120" show-overflow-tooltip></el-table-column>
            </el-table>
            <span slot="footer" class="dialog-footer">
            <el-button @click="opinionDialogVisible3 = false">返 回</el-button>
        </span>
        </el-dialog>

 -->
        <!-- 查看日志 -->
        <el-dialog
                title="查看日志"
                :visible.sync="showLog"
                width="60%"
                center>
            <el-row style="margin-bottom: 5px">
                <el-col :span="16">
                    <el-col :span="10">
                        <label class="complain-lab">打印日期</label>
                    </el-col>
                    <el-col :span="14">
                        <el-date-picker
                                v-model="printTime"
                                type="datetimerange"
                                align="right"
                                start-placeholder="开始日期"
                                end-placeholder="结束日期"
                                :default-time="['09:00:00', '23:59:59']">
                        </el-date-picker>
                    </el-col>
                </el-col>
                <el-col :span="8" >
                    <el-button type="primary" icon="el-icon-search" @click="showLogs"></el-button>
<!--                    <el-button type="primary" plain icon="el-icon-refresh" @click="refresh"></el-button>-->
                </el-col>
            </el-row>
            <el-table :data="logs" @row-click="showBmntdesc">
                <el-table-column property="printTime" label="打印时间" min-width="120" ></el-table-column>
                <el-table-column property="logDesc" label="日志" min-width="400" ></el-table-column>
            </el-table>
            <el-row>
                <el-col :span="24">
                    <div class="pagination">
                        <el-pagination
                                background
                                v-if='paginations.total > 0'
                                :page-sizes="paginations.pageSizes"
                                :page-size="paginations.pageSize"
                                :layout="paginations.layout"
                                :total="paginations.total"
                                :current-page='paginations.pageIndex'
                                @current-change='handleCurrentChange'
                                @size-change='handleSizeChange'>
                        </el-pagination>
                    </div>
                </el-col>
            </el-row>

            <el-row>
                <span class="tips" v-if="isShowBmntdesc">点击列表中日志可在下方文本域中展示详细信息：</span>
                <el-input v-model="logDesc" v-if="isShowBmntdesc"
                          type="textarea"
                          :rows="10"
                >
                </el-input>
            </el-row>
            <span slot="footer" class="dialog-footer">
            <el-button @click="showLog = false">返 回</el-button>
        </span>
        </el-dialog>

    </div>
</template>
<script>
  import constant from '@/utils/constant';
  import appName from '@/api/appName';
  import {getToken, setCookie} from '@/utils/auth';
  import uwLoadJs from '@/utils/uwLoad';
  import moment from 'moment';
  export default {
    data() {
      return {
        showLog: false,
        opinionDialogVisible3: false,
        opinionDialogVisible2: false,
        opinionDialogVisible1: false,
        amounts: [],
        real: [],
        name: "",
        crts:[],
        paginations: {
          total: 0,        // 总数
          pageIndex: 1,  // 当前位于哪页
          pageSize: 10,   // 1页显示多少条
          pageSizes: [5, 10, 15, 20],  //每页显示多少条
          layout: "total, sizes, prev, pager, next, jumper",   // 翻页属性
          printTime: '',
        },
        logs:[],
        logDesc:"",
        printTime:'',
        isShowBmntdesc:false,
          showLogsTimeOut:null,
          initAmountTimeOut:null
      }
    },
    props: {
      cumAmountFlag: {
        type: Boolean,
        default: false
      },
      clntnum: {
        type: String,
        default: false
      },
	  showAmount: {
		  type : String,
		  default: ''
	  },
	  applnum : {
		  type : String,
		  default :''
	  },
	  name : {
		  type : String,
		  default : ''
	  }
    },
      destroyed() {
        clearTimeout(this.showLogsTimeOut)
          clearTimeout(this.initAmountTimeOut)
      },
      methods: {
		changeValue(row) {
			if(row.reinsdate == "0") {
				return "";
			}
			return row.reinsdate;
		},
      changeView() {
        this.$emit('subCumAmountFlag', false);
      },

      handleCurrentChange(page) {
        this.paginations.pageIndex = page;
        this.showLogs();
      },

      handleSizeChange() {
        this.paginations.pageSize = pageSize;
        this.showLogs();
      },
      showBmntdesc(row, column, event) {
        this.logDesc = row.logDesc;
      },
      refresh(){
        this.paginations.printTime = [];
      },

      //查看日志
      showLogs(){
        let that = this;
        this.showLog = true;
        let time = "";
        let begin = "";
        let end = "";
        if(this.printTime){
          let printTimeL = this.printTime[0];
          begin = moment(printTimeL).format('YYYY-MM-DD HH:mm:ss')
          let printTimeR = this.printTime[1];
          end = moment(printTimeR).format('YYYY-MM-DD HH:mm:ss');
          time = "&printTimeL="+moment(begin).format('YYYY-MM-DD HH:mm:ss')+"&printTimeR="+moment(end).format('YYYY-MM-DD HH:mm:ss');
        }
        // let url = appName.SYSTEM+"/log/business/page?platform=amount-app&busiCode="+this.clntnum+"&pageSize="
        //   +this.paginations.pageSize+"&pageNumber="+this.paginations.pageIndex+time;

        let url1 = appName.SYSTEM+"/log/business/pageList";
        let pramrs = {
          "printTimeL": begin,
          "printTimeR": end,
          "busiCode":this.clntnum,
          "platform":'amount-app',
          "pageSize":this.paginations.pageSize,
          "pageNumber":this.paginations.pageIndex,
        }
        that.$emit('showLoading',true);
        this.showLogsTimeOut = setTimeout(function(){
          let res = uwLoadJs.ajaxRequest(pramrs,url1);
          that.$emit('showLoading',false);
          if (res.resultCode == constant.SUCCESS && res.data!=null) {
            that.logs = res.data.rows;
            that.paginations.total = res.data.total
            if(that.logs.length>0){
              that.isShowBmntdesc = true;
            }
          }
          console.log(that.printTime);
        },100)

      },

      //详情
      details(data){
        this.crts = data.crtLists;
		//处理本次的
		if('Y'== this.showAmount) {
			this.crts.forEach( item =>{
				this.real.forEach( ite =>{
					//同一个计算险种
					if (ite.name ==data.name) {
						ite.crtLists.forEach( one =>{
							//匹配eu001计算返回的
							if (one.crtable == item.crtable ) {
								item['realCount'] = one.count;
								item['realsuminsorg'] = one.suminsorg
							}
						})
					}
				})
			} ) 

		}
        this.opinionDialogVisible1 = true;
      },
      //更多
      more() {
        this.opinionDialogVisible2 = true;
      },
      //初始化保额信息
      initAmount() {
        let that = this;
        debugger
        console.log(this.showAmountList);
		
        let params = {
          "clntnum": this.clntnum,
		  "showAmount":this.showAmount,
		  "applnum":this.applnum
        }
        that.$emit('showLoading',true);
        this.initAmountTimeOut = setTimeout(function(){
          that.$.ajax({
            headers: {
              Authorization: getToken(constant.TOKEN) || ''
            },
            url: appName.NEWUNDR + '/unipnd/amount/initAmount',//url路径
            type: 'POST', //GET
            async: false, //或false,是否异步
            data: JSON.stringify(params),
            contentType: "application/json;charset=UTF-8",
            success: function (res, textStatus, jqXHR) {
              that.$emit('showLoading',false);
              if (res.resultCode == constant.SUCCESS && res.data != null) {
                that.amounts = res.data.list;
                // that.name = res.data.name;
                that.real = res.data.real;
              } else {
                that.$message({
                  message: res.resultMsg,
                  type: 'error'
                });

              }
            }

          })
        },100)

      },
      // 主约险种累计保额
      insuranceShow() {
        this.opinionDialogVisible3 = true;
      },
    },
    created() {
      this.initAmount();
    }
  }
</script>
<style lang="less" scoped>
    .tips{
        color: #f76565;
    }
    .ml10{    margin-left: 10px;}
 .txt-right{text-align: right;padding-right:10px;}
</style>